1
using System
.Collections
;
2 using System
.Collections
.Generic
;
4 using UnityEngine
.SceneManagement
;
6 using UnityEngine
.EventSystems
;
8 public class UpgradeUI
: MonoBehaviour
{
11 GameObject upgradePanel
;
13 GameObject successPanel
;
16 GameObject successPanelYes
;
19 //health upgrade panel
21 GameObject shipHealthPanel
;
23 GameObject shipHealthButton1
;
27 Button shipMovementButton1
;
29 GameObject health1Upgrade
;
33 GameObject health2Upgrade
;
37 GameObject health3Upgrade
;
47 Button shipHealthButton2
;
49 GameObject ammoButton2
;
51 Button shipMovementButton2
;
53 GameObject ammo1Upgrade
;
57 GameObject ammo2Upgrade
;
65 GameObject shipMovementPanel
;
67 Button shipHealthButton3
;
71 GameObject shipMovementButton3
;
73 GameObject movement1Upgrade
;
77 GameObject movement2Upgrade
;
87 GameObject confirmationPanel
;
99 public float upgradeWindowDelay
;
100 public float successWindowDelay
;
103 public static bool startNextLevel
;
104 private GameManager gameManager
;
105 private HealthSlider hp
;
106 private StationNav stationNav
;
107 private float upgardeWindowTimer
= 0;
108 private float successWindowTimer
= 0;
109 private bool canDisplayUpgrade
=true;
111 // Use this for initialization
113 startNextLevel
= false;
114 shipHealthPanel
.SetActive(true);
115 ammoPanel
.SetActive(false);
116 shipMovementPanel
.SetActive(false);
117 shipHealthButton1
.GetComponent
<Button
>().interactable
= false;
118 confirmationPanel
.SetActive(false);
119 GameObject gameManagerObject
= GameObject
.FindWithTag("GameManager");
120 if (gameManagerObject
)
122 gameManager
= gameManagerObject
.GetComponent
<GameManager
>();
124 GameObject hpObject
= GameObject
.FindGameObjectWithTag("YarnPhysics");
127 hp
= hpObject
.GetComponent
<HealthSlider
>();
129 GameObject navGameObject
= GameObject
.FindGameObjectWithTag("NavigationStation");
132 stationNav
= navGameObject
.GetComponent
<StationNav
>();
135 health1Price
.text
= movement1Price
.text
= ammo1Price
.text
= GameManager
.priceList
[0].ToString();
136 health2Price
.text
= movement2Price
.text
= ammo2Price
.text
= GameManager
.priceList
[1].ToString();
137 health3Price
.text
= GameManager
.priceList
[2].ToString();
138 SetButtonInteactive();
141 // Update is called once per frame
143 moneyText
.text
= GameManager
.money
.ToString();
144 if (!(gameManager
.HelloGrandma()) && hp
.LevelEnded
&& !upgradePanel
.activeSelf
&&canDisplayUpgrade
)
146 if(upgardeWindowTimer
>=upgradeWindowDelay
)
148 activateUpgradePanel();
149 upgardeWindowTimer
= 0;
153 upgardeWindowTimer
+= Time
.deltaTime
;
156 else if((gameManager
.HelloGrandma()) && hp
.BossEnded
&& !successPanel
.activeSelf
)
158 if (successWindowTimer
>= successWindowDelay
)
160 activateSuccessPanel();
161 successWindowTimer
= 0;
165 successWindowTimer
+= Time
.deltaTime
;
170 private void activateUpgradePanel()
172 upgradePanel
.SetActive(true);
173 EventSystem
.current
.SetSelectedGameObject(shipHealthButton1
, null);
177 private void activateSuccessPanel()
179 successPanel
.SetActive(true);
180 EventSystem
.current
.SetSelectedGameObject(successPanelYes
, null);
183 public void shipHealthPanelActive()
185 if(!shipHealthPanel
.activeSelf
)
187 shipHealthPanel
.SetActive(true);
188 ammoPanel
.SetActive(false);
189 shipMovementPanel
.SetActive(false);
190 shipHealthButton1
.GetComponent
<Button
>().interactable
= false;
191 EventSystem
.current
.SetSelectedGameObject(shipHealthButton1
, null);
192 ammoButton1
.interactable
= true;
193 shipMovementButton1
.interactable
= true;
196 public void ammoPanelActive()
198 if (!ammoPanel
.activeSelf
)
200 ammoPanel
.SetActive(true);
201 shipHealthPanel
.SetActive(false);
202 shipMovementPanel
.SetActive(false);
203 ammoButton2
.GetComponent
<Button
>().interactable
= false;
204 EventSystem
.current
.SetSelectedGameObject(ammoButton2
, null);
205 shipHealthButton2
.interactable
= true;
206 shipMovementButton2
.interactable
= true;
211 public void shipMovementPanelActive()
213 if (!shipMovementPanel
.activeSelf
)
215 shipMovementPanel
.SetActive(true);
216 ammoPanel
.SetActive(false);
217 shipHealthPanel
.SetActive(false);
218 shipMovementButton3
.GetComponent
<Button
>().interactable
= false;
219 EventSystem
.current
.SetSelectedGameObject(shipMovementButton3
, null);
220 shipHealthButton3
.interactable
= true;
221 ammoButton3
.interactable
= true;
226 public void closeUpgradePanel()
228 upgradePanel
.SetActive(false);
229 confirmationPanel
.SetActive(true);
230 EventSystem
.current
.SetSelectedGameObject(yesButton
, null);
231 canDisplayUpgrade
= false;
234 public void GoToMainMenu()
236 GameObject menuManager
= GameObject
.FindGameObjectWithTag ("MenuManager");
237 if (menuManager
!= null)
239 MenuManager menuManagerScript
= menuManager
.GetComponent
<MenuManager
> ();
240 menuManagerScript
.PlayMenuSel ();
241 menuManagerScript
.StartMenuMusic ();
243 SceneManager
.LoadScene("MainMenu");
246 public void YesButtonClicked()
248 startNextLevel
= true;
249 confirmationPanel
.SetActive(false);
250 //upgradePanel.SetActive(false);
253 public void NoButtonClicked()
255 confirmationPanel
.SetActive(false);
256 upgradePanel
.SetActive(true);
257 shipHealthPanel
.SetActive(true);
258 ammoPanel
.SetActive(false);
259 shipMovementPanel
.SetActive(false);
260 canDisplayUpgrade
= true;
261 EventSystem
.current
.SetSelectedGameObject(shipHealthButton1
, null);
266 public void QuitGame()
272 public void healthUpdate1()
274 Navigation nonNav
= new Navigation();
275 nonNav
.mode
= Navigation
.Mode
.None
;
276 if (GameManager
.money
>= GameManager
.priceList
[0])
278 health1Upgrade
.GetComponent
<Button
>().navigation
= nonNav
;
279 health1Upgrade
.GetComponent
<Button
>().interactable
= false;
280 health2Upgrade
.GetComponent
<Button
>().interactable
= true;
281 EventSystem
.current
.SetSelectedGameObject(health2Upgrade
, null);
282 hp
.UpgradeMaxHealth(GameManager
.healthUpgradeValue
[0]);
283 gameManager
.spendCoin(GameManager
.priceList
[0]);
285 GameManager
.healthUpgradeAvailability
[0] = false;
286 GameManager
.healthUpgradeAvailability
[1] = true;
291 public void healthUpdate2()
293 Navigation nonNav
= new Navigation();
294 nonNav
.mode
= Navigation
.Mode
.None
;
295 if (GameManager
.money
>= GameManager
.priceList
[1])
297 health2Upgrade
.GetComponent
<Button
>().navigation
= nonNav
;
298 health2Upgrade
.GetComponent
<Button
>().interactable
= false;
299 health3Upgrade
.GetComponent
<Button
>().interactable
= true;
300 EventSystem
.current
.SetSelectedGameObject(health3Upgrade
, null);
301 hp
.UpgradeMaxHealth(GameManager
.healthUpgradeValue
[1]);
302 gameManager
.spendCoin(GameManager
.priceList
[1]);
304 GameManager
.healthUpgradeAvailability
[1] = false;
305 GameManager
.healthUpgradeAvailability
[2] = true;
310 public void healthUpdate3()
312 Navigation nonNav
= new Navigation();
313 nonNav
.mode
= Navigation
.Mode
.None
;
314 if (GameManager
.money
>= GameManager
.priceList
[2])
316 health3Upgrade
.GetComponent
<Button
>().navigation
= nonNav
;
317 health3Upgrade
.GetComponent
<Button
>().interactable
= false;
318 EventSystem
.current
.SetSelectedGameObject(shipHealthButton1
, null);
319 hp
.UpgradeMaxHealth(GameManager
.healthUpgradeValue
[2]);
320 gameManager
.spendCoin(GameManager
.priceList
[2]);
322 GameManager
.healthUpgradeAvailability
[2] = false;
326 public void ammoUpgrade1()
328 Navigation nonNav
= new Navigation();
329 nonNav
.mode
= Navigation
.Mode
.None
;
330 if (GameManager
.money
>= GameManager
.priceList
[0])
332 ammo1Upgrade
.GetComponent
<Button
>().navigation
= nonNav
;
333 ammo1Upgrade
.GetComponent
<Button
>().interactable
= false;
334 ammo2Upgrade
.GetComponent
<Button
>().interactable
= true;
335 EventSystem
.current
.SetSelectedGameObject(ammo2Upgrade
, null);
336 GameManager
.ammoTypeUnlocked
[0] = true;
337 gameManager
.spendCoin(GameManager
.priceList
[0]);
339 GameManager
.ammoUpgradeAvailability
[0] = false;
340 GameManager
.ammoUpgradeAvailability
[1] = true;
344 public void ammoUpgrade2()
346 Navigation nonNav
= new Navigation();
347 nonNav
.mode
= Navigation
.Mode
.None
;
348 if (GameManager
.money
>= GameManager
.priceList
[1])
350 ammo2Upgrade
.GetComponent
<Button
>().navigation
= nonNav
;
351 ammo2Upgrade
.GetComponent
<Button
>().interactable
= false;
352 EventSystem
.current
.SetSelectedGameObject(ammoButton2
, null);
353 GameManager
.ammoTypeUnlocked
[1] = true;
354 gameManager
.spendCoin(GameManager
.priceList
[1]);
356 GameManager
.ammoUpgradeAvailability
[1] = false;
361 public void movementUpdate1()
363 Navigation nonNav
= new Navigation();
364 nonNav
.mode
= Navigation
.Mode
.None
;
365 if (GameManager
.money
>= GameManager
.priceList
[0])
367 movement1Upgrade
.GetComponent
<Button
>().navigation
= nonNav
;
368 movement1Upgrade
.GetComponent
<Button
>().interactable
= false;
369 movement2Upgrade
.GetComponent
<Button
>().interactable
= true;
370 EventSystem
.current
.SetSelectedGameObject(movement2Upgrade
, null);
371 stationNav
.UpgradeTorque(GameManager
.torqueIncrease
);
372 gameManager
.spendCoin(GameManager
.priceList
[0]);
374 GameManager
.movementUpgradeAvailability
[0] = false;
375 GameManager
.movementUpgradeAvailability
[1] = true;
381 public void movementUpgrade2()
383 Navigation nonNav
= new Navigation();
384 nonNav
.mode
= Navigation
.Mode
.None
;
385 if (GameManager
.money
>= GameManager
.priceList
[1])
387 movement2Upgrade
.GetComponent
<Button
>().navigation
= nonNav
;
388 movement2Upgrade
.GetComponent
<Button
>().interactable
= false;
389 EventSystem
.current
.SetSelectedGameObject(shipMovementButton3
, null);
390 hp
.UpGradeInvulnerability(GameManager
.invulnerabilityTimerIncrease
);
391 gameManager
.spendCoin(GameManager
.priceList
[1]);
393 GameManager
.movementUpgradeAvailability
[1] = false;
398 private void SetButtonInteactive()
400 health1Upgrade
.GetComponent
<Button
>().interactable
= GameManager
.healthUpgradeAvailability
[0];
401 health2Upgrade
.GetComponent
<Button
>().interactable
= GameManager
.healthUpgradeAvailability
[1];
402 health3Upgrade
.GetComponent
<Button
>().interactable
= GameManager
.healthUpgradeAvailability
[2];
403 ammo1Upgrade
.GetComponent
<Button
>().interactable
= GameManager
.ammoUpgradeAvailability
[0];
404 ammo2Upgrade
.GetComponent
<Button
>().interactable
= GameManager
.ammoUpgradeAvailability
[1];
405 movement1Upgrade
.GetComponent
<Button
>().interactable
= GameManager
.movementUpgradeAvailability
[0];
406 movement2Upgrade
.GetComponent
<Button
>().interactable
= GameManager
.movementUpgradeAvailability
[1];
409 public void PlayCoinSound()
411 GameObject ExtraSFX
= GameObject
.FindGameObjectWithTag ("ExtraSFX");
412 AudioSource
[] audioSources
= ExtraSFX
.GetComponents
<AudioSource
> ();
413 AudioSource coinSound
= audioSources
[2];